﻿using Allin.Abp.AspNetCore.Components.Web.Theming.Toolbars;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Allin.Abp.AspNetCore.Components.Web.AntDesignTheme.Themes.AntDesign;

public partial class ToolbarItemsComponent
{
	[Inject] private IToolbarManager ToolbarManager { get; set; }

	[Parameter] public string Name { get; set; }

	private List<RenderFragment> ToolbarItemRenders { get; set; } = new List<RenderFragment>();

	protected override async Task OnInitializedAsync()
	{
		var toolbar = await ToolbarManager.GetAsync(Name ?? StandardToolbars.Main);

		ToolbarItemRenders.Clear();

		foreach (var item in toolbar.Items)
		{
			ToolbarItemRenders.Add(builder =>
			{
				builder.OpenComponent(0, item.ComponentType);
				builder.CloseComponent();
			});
		}
	}
}